Persist message history to local storage #346
Open
+197
−38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@andrewheadricke's work to persist messages to localStorage in #342 piqued my interest so I took a stab at fleshing it out. This feature is requested in issue #162.
I've created a
MessageStore
class which handles the CRUD operations on messages in localStorage. Each message is stored in a separate localStorage item to facilitate paginated loading on scroll.What's in the box:
I have never used zustand and immer so I wasn't sure how to best link this in with the deviceState. I had an issue where the ChannelChat component was not updating with new messages and state changes. To get it functional I resorted to a semaphore on the deviceState which is clearly not the best but it works. Any suggestions on how to improve this would be most welcome!